package top.goldenyear.porpoise.framework.web.core.generator.config;

import com.jfinal.kit.Kv;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 模块配置，对应mvc，dto和前端模块
 * @author airhead
 */
@Data
@Accessors(chain = true)
public class ModuleConfig extends Kv {
  private PackageConfig packageConfig;

  /** module，对应的 mvc 等模块类型 */
  private String module;

  private String outputFile = "#(sourcesRoot)/#(moduleFile)";
  private String fileSuffix = ".java";
  private String template;

  private String classPrefix = "";
  private String classSuffix = "";
  private Boolean chainSetter = false;
  private Class<?> superClass;
  private Class<?> superInterface;

  /** 模块本身是否支持覆盖 */
  private Boolean overwrite = false;

  /** 外部配置是否强制进行覆盖 */
  private Boolean enableOverwrite = false;

  public static ModuleConfig of() {
    return new ModuleConfig();
  }

  public Boolean needWrite() {
    // 如果配置了强制生成，则强制生成
    if (Boolean.TRUE.equals(enableOverwrite)) {
      return true;
    }

    // 检查模块是否支持覆盖
    return Boolean.TRUE.equals(overwrite);
  }
}
